package com.framework.seedkit.device.nfc;

import android.content.Intent;
import android.os.Bundle;

import com.framework.seedkit.R;
import com.framework.seedkit.base.BaseActivity;

/**
 * Created by ekimatsu on 16/12/27.
 */

public class NfcConnectAct extends BaseActivity {
    NFCUtil mNFCUtil;

    /**
     * @Fields mOpenForegroundPush : 打开NFC初始化开关
     */
    protected boolean mOpenForegroundPushTag = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mNFCUtil = new NFCUtil(this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        if (mOpenForegroundPushTag) {
            if (needSupportForegroundNFC()) {

                mNFCUtil.enableForegroundDispatch();

                if (mNFCUtil.isNFCAction(getIntent())) {
                    mNFCUtil.updateNfcMSG(getIntent());// 更新NFC消息
                }
            }
        }
    }

    /**
     * @Title: needSupportForegroundNFC
     * @Description: 当前Activity是否需要支持前景
     * @return
     * @returnType boolean
     */
    protected boolean needSupportForegroundNFC() {
        return mNFCUtil.isSupportNFC() && mOpenForegroundPushTag;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.act_nfc_layout;
    }

    @Override
    public void initView() {
        super.initView();
    }

    @Override
    public void initData() {
        super.initData();
    }

    @Override
    protected void onPause() {
        super.onPause();

        if (mOpenForegroundPushTag) {
            if (needSupportForegroundNFC()) {
                mNFCUtil.disableForegroundDispatch();
            }
        }
    }
}
